/**
 * OSS is a Open Service Container which gives the leverage of building the Desktop and Web
 * Application. * Copyright (C) 2008-2009  Ponraj Sutanthiramani
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Or5e Open Source Community
 * Navigator Bldg, ITPL, Bangalore, India.
 */

package org.or5e.api.liveradio;

import java.util.Set;

/**
 * This is the Factory using which we can create the Live Radio instance. This comes
 * with two flavours you can get the default implemented SPI or custom Implementaion.
 * @author Pornaj Suthanthiramani
 * @version 1.0b
 */
public class LiveRadioFactory {
    private static LiveRadio _radio = null;


    /**
     * This will return the Default SPI impmentation of the Live Radio.
     * @return
     */
    public static LiveRadio getLiveRadio() {
        return getLiveRadio("org.or5e.core.api.liveradio.LiveRadioSpi");
    }

    /**
     * If you have the Custom implementaion of this API you can provide the SPI Class
     * available in the market.
     * @param radioSPI
     * @return
     */
    public static LiveRadio getLiveRadio(String radioSPI) {
        if(_radio == null) {
            try {
                _radio = (LiveRadio) Class.forName(radioSPI).newInstance();
            }
            catch(ClassNotFoundException cnf) {

            }
            catch (InstantiationException ex) {
                
            }
            catch (IllegalAccessException ex) {
                
            }
            catch(RuntimeException ex) {
                
            }
        }
        return _radio;
    }

    public static void main(String[] args) throws LiveRadioException {
        System.setProperty("http.proxyHost", "www-ad-proxy.sabre.com");
        System.setProperty("http.proxyPort", "80");
        LiveRadio rad = LiveRadioFactory.getLiveRadio();
        rad.initilizeRadioChannels(null, null);
        Set<String> availChannelList = rad.getAvailableChannelList();
        for (String channel : availChannelList) {
            if(channel.contains("Tamil")) {
                RadioInfo radInfo = rad.getChannelInfo(channel);
                System.out.println("Radio Info :"+radInfo);
                rad.playChannel(channel);
                break;
            }
        }
        System.out.println("Live Radio :"+availChannelList.size());
    }
}
